package com.dh.project.utils;

import com.dh.project.model.*;
import com.dh.project.view.CustomerIdeaListView;
import com.dh.project.view.MaintainListView;
import com.dh.project.view.OrderListView;

/**
 * Created by admin on 2017/4/10.
 */
public class PageUtil {


    public static Integer getPageCount(Integer count,int page_count){

        int pageCount = 0;

        if (count == 0){
            pageCount = 1;
        }

        if (count % page_count == 0){
            pageCount =count / page_count;
        }else {
            pageCount = (count / page_count) + 1;
        }
        return pageCount;
    }

    /**
     * 获取每页显示数据数量的对象
     * @param pageModel
     * @param page
     * @param page_count
     * @return
     */
    public static PageInfo getPageInfo(PageModel pageModel,int page,int page_count){
        PageInfo pageInfo = new PageInfo();
        pageInfo.setCount_info(pageModel.getPage_index());

        if (page <= 1){
            pageInfo.setStart_info(1);
        }else {
            pageInfo.setStart_info((page-1)*10);
        }

        if ((page * page_count) <= pageModel.getPage_index()){
            pageInfo.setEnd_info(page * page_count);
        }else {
            pageInfo.setEnd_info(pageModel.getPage_index());
        }
        return pageInfo;
    }

    public static String getPageHrefFour(Object obj, int type){
        String id = null,name = null,start_href = null,id_href = null,name_href = null;
        if (type == 1){
            CustomerIdeaListView customerIdeaListView = (CustomerIdeaListView) obj;
            id = customerIdeaListView.getStart_date();
            name = customerIdeaListView.getEnd_date();
            start_href = "selectCustomerIdeaList?";
            id_href = "start_date=";
            name_href = "end_date=";
        }

        String page_href = "";
        if (id != null && name != null){
            page_href = start_href+id_href+id+"&"+name_href+name+"&page=";
        }else if (id != null){
            page_href = start_href+id_href+id+"&page=";
        }else if (name != null){
            page_href = start_href+name_href+name+"&page=";
        }else {
            page_href = start_href+"page=";
        }
        return  page_href;
    }

    /**
     * 获取分页链接(2条件)
     * @param obj
     * @param type
     * @return
     */
    public static String getPageHref(Object obj, int type){
        Integer id = null;
        String name = null,start_href = null,id_href = null,name_href = null;
        if (type == 1){
            Admin admin = (Admin) obj;
            id = admin.getAdmin_id();
            name = admin.getAdmin_name();
            start_href = "selectAdminList?";
            id_href = "admin_id=";
            name_href = "admin_name=";
        }else if (type == 2){
            CustomerInfo customerInfo = (CustomerInfo) obj;
            id =customerInfo.getCustomer_id();
            name = customerInfo.getCustomer_phone();
            start_href = "selectCustomerList?";
            id_href = "customer_id=";
            name_href = "customer_phone=";
        }else if (type == 3){
            EmployeeInfo employeeInfo = (EmployeeInfo) obj;
            id = employeeInfo.getEmployee_id();
            name = employeeInfo.getEmployee_name();
            start_href = "selectEmployeeList?";
            id_href = "employee_id=";
            name_href = "employee_name=";
        }else if (type == 4){
            EngineerPhone engineerPhone = (EngineerPhone) obj;
            id = engineerPhone.getEngineer_id();
            name = engineerPhone.getEngineer_name();
            start_href = "selectEngineerPhoneList?";
            id_href = "engineer_id=";
            name_href = "engineer_name=";
        }else if (type == 5){
            LableInfo lableInfo = (LableInfo) obj;
            id = lableInfo.getLable_class_one();
            name = String.valueOf(lableInfo.getLable_type());
            start_href = "selectLableInfo?";
            id_href = "lable_class_one=";
            name_href = "lable_type=";
        }else if (type == 6){
            Coupon coupon = (Coupon) obj;
            id = coupon.getId();
            name = coupon.getCoupon_name();
            start_href = "selectCouponList?";
            id_href = "id=";
            name_href = "coupon_name=";
        }else if (type == 7){
            Coupon coupon = (Coupon) obj;
            id = coupon.getId();
            name = coupon.getCoupon_name();
            start_href = "selectCouponDetail?";
            id_href = "id=";
            name_href = "coupon_name=";
        }else if (type == 8){
            Coupon coupon = (Coupon) obj;
            id = coupon.getId();
            name = coupon.getCoupon_name();
            start_href = "selectCouponGetList?";
            id_href = "id=";
            name_href = "coupon_name=";
        }

        String page_href = "";
        if (id != null && name != null){
            page_href = start_href+id_href+id+"&"+name_href+name+"&page=";
        }else if (id != null){
            page_href = start_href+id_href+id+"&page=";
        }else if (name != null){
            page_href = start_href+name_href+name+"&page=";
        }else {
            page_href = start_href+"page=";
        }
        return  page_href;
    }


    public static String getPageHrefThree(Object obj, int type){
        Integer order_type = null,order_status = null,order_id = null;

        String name = null,start_href = null,id_href = null,name_href = null,phone= null,phone_hred=null,status_href=null,order_id_href=null;

        Double max_price=0.0,min_price=0.0;
        String max_price_href=null,min_price_href=null;

        if (type == 1){
            OrderListView orderListView = (OrderListView) obj;
            order_type = orderListView.getOrder_type();
            name = orderListView.getCustomer_name();
            phone = orderListView.getRelation_phone();
            order_status = orderListView.getOrder_status();
            start_href = "selectOrderList?";
            id_href = "order_type=";
            name_href = "customer_name=";
            phone_hred = "customer_phone=";
            status_href = "order_status=";
        }if (type == 2){
            MaintainListView serviceProject = (MaintainListView) obj;
            max_price = serviceProject.getMax_price();
            min_price = serviceProject.getMin_price();
            order_type = serviceProject.getService_kind();
            start_href = "selectMaintainList?";

            max_price_href = "max_price=";
            min_price_href = "min_price=";
            id_href = "service_kind=";
        }
        String page_href = start_href;
        if (order_type != null){
            page_href = page_href + id_href + order_type;
        }
        if (name != null){
            page_href = page_href +"&"+ name_href +name;
        }
        if (phone != null){
            page_href = page_href +"&"+ phone_hred +phone;
        }
        if (order_status != null){
            page_href = page_href +"&"+ status_href +order_status;
        }
        if (max_price != null){
            page_href = page_href +"&"+ max_price_href +max_price;
        }
        if (min_price != null){
            page_href = page_href +"&"+ min_price_href +min_price;
        }
        page_href = page_href + "&page=";
        return  page_href;
    }


    /**
     *  产品类 5条件获取分页链接
     * @param obj
     * @param type
     * @return
     */
    public static String getPageHrefByFive(Object obj, int type){
        Integer condition_one = null,condition_two = null, condition_three = null ,condition_four = null, condition_five = null;
        String one_href = null,two_href = null,three_href = null,four_href=null,five_href = null, start_href = null;
        if (type == 1){//产品
            ServiceProject serviceProject = (ServiceProject) obj;
            //分类  空调 地暖 新风  7.维修类
            condition_one = serviceProject.getService_class();
            //品牌
            condition_two = serviceProject.getService_brand();
            //种类
            condition_three = serviceProject.getService_kind();
            //规格
            condition_four = serviceProject.getService_standard();
            //部件
            condition_five = serviceProject.getService_assembly();
            start_href = "selectServiceProjectList?";
            one_href = "service_class=";
            two_href = "service_brand=";
            three_href = "service_kind=";
            four_href = "service_standard=";
            five_href = "service_assembly=";
        }else if (type == 2){//维修
            ServiceProject serviceProject = (ServiceProject) obj;
            //分类  空调 地暖 新风  7.维修类
            condition_one = serviceProject.getService_class();
            start_href = "selectServiceProjectList?";
            one_href = "service_class=";
        }else if (type == 3){//产品
            ServiceProject serviceProject = (ServiceProject) obj;
            //分类  空调 地暖 新风  7.维修类
            condition_one = serviceProject.getService_class();
            //品牌
            condition_two = serviceProject.getService_brand();
            //种类
            condition_three = serviceProject.getService_kind();
            //规格
            condition_four = serviceProject.getService_standard();
            //部件
            condition_five = serviceProject.getService_assembly();
            start_href = "OrderAddServiceProject?";
            one_href = "service_class=";
            two_href = "service_brand=";
            three_href = "service_kind=";
            four_href = "service_standard=";
            five_href = "service_assembly=";
        }
        String page_href = "";
        String one_page_href = "";
        if (condition_one != null){
            one_page_href = one_href+condition_one;
        }
        if (condition_two != null){
            if (one_page_href.equals("")){
                one_page_href = two_href+condition_two;
            }else {
                one_page_href = one_page_href+"&"+two_href+condition_two;
            }
        }
        if (condition_three != null){
            if (one_page_href.equals("")){
                one_page_href = three_href+condition_three;
            }else {
                one_page_href = one_page_href+"&"+three_href+condition_three;
            }
        }
        if (condition_four != null){
            if (one_page_href.equals("")){
                one_page_href = four_href+condition_four;
            }else {
                one_page_href = one_page_href+"&"+four_href+condition_four;
            }
        }
        if (condition_five != null){
            if (one_page_href.equals("")){
                one_page_href = five_href+condition_five;
            }else {
                one_page_href = one_page_href+"&"+five_href+condition_five;
            }
        }

        if (one_page_href.equals("")){
            page_href = start_href+"&page=";
        }else {
            page_href = start_href+one_page_href+"&page=";
        }
        return  page_href;
    }
}
